<template>
  <div class="app-container">

    <el-table v-loading="loading" :data="memberpriceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="会员价格" align="center" prop="amountMoney" />
      <el-table-column label="拼团价格" align="center" prop="collageMoney" />
      <el-table-column label="会员详情" align="center" prop="content" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['generator:memberprice:edit']">修改</el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改会员价格对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="会员价格" prop="amountMoney">
          <el-input-number v-model="form.amountMoney" placeholder="请输入会员价格" />
        </el-form-item>
        <el-form-item label="拼团价格" prop="collageMoney">
          <el-input-number v-model="form.collageMoney" placeholder="请输入拼团价格" :point="2" />
        </el-form-item>
        <el-form-item label="会员详情">
          <el-input v-model="form.content" placeholder="请输入拼团价格" type="textarea" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMemberprice, getMemberprice, delMemberprice, addMemberprice, updateMemberprice } from "@/api/generator/memberprice";

export default {

  name: "Memberprice",
  data () {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会员价格表格数据
      memberpriceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        amountMoney: null,
        collageMoney: null,
        content: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        amountMoney: [
          {
            required: true,
          }
        ],
        collageMoney: [
          {
            required: true,
          }
        ],
      }
    };
  },
  created () {
    this.getList();
  },
  methods: {
    /** 查询会员价格列表 */
    getList () {
      this.loading = true;
      listMemberprice(this.queryParams).then(response => {
        this.memberpriceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        id: null,
        amountMoney: null,
        collageMoney: null,
        content: null
      };
      this.resetForm("form");
    },

    /** 修改按钮操作 */
    handleUpdate (row) {
      this.reset();
      const id = row.id || this.ids
      getMemberprice(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改会员价格";
      });
    },
    /** 提交按钮 */
    submitForm () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateMemberprice(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },

  }
};
</script>
